define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'disassemble/money/index' + location.search,
                    // add_url: 'disassemble/money/add',
                    edit_url: 'disassemble/money/edit',
                    // del_url: 'disassemble/money/del',
                    multi_url: 'disassemble/money/multi',
                    // import_url: 'disassemble/money/import',
                    do_url: 'disassemble/money/do_status',
                    table: 'store_back_price',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'store.name', title: __('厂商'), operate:'LIKE'},
                        // {field: 'priceid', title: __('Priceid')},
                        {field: 'price.type', title: __('Price.type'), searchList: {"1":__('Price.type 1'),"2":__('Price.type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'price.first_id', title: __('一级类目'), operate:false},
                        {field: 'price.second_id', title: __('二级类目'), operate:false},
                        {field: 'price.level', title: __('Price.level'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'price.weight', title: __('Price.weight'), operate:'BETWEEN'},
                        {field: 'price.end', title: __('Price.end'), operate:'BETWEEN'},
                        {field: 'price.price', title: __('Price.price'), operate:'BETWEEN'},
                        {field: 'price.yprice', title: __('Price.yprice'), operate:'BETWEEN'},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'ymoney', title: __('Ymoney'), operate:'BETWEEN'},
                        {field: 'price.desc', title: __('Price.desc'),formatter : function(value, row, index, field){
                                return "<span style='display: block;overflow: hidden;text-overflow: ellipsis;white-space:nowrap;' title='" + row.price.desc + "'>" + value + "</span>";
                            },
                            cellStyle : function(value, row, index, field) {
                                return {
                                    css: {
                                        "white-space": "nowrap",
                                        "text-overflow": "ellipsis",
                                        "overflow": "hidden",
                                        "max-width": "200px"
                                    }
                                };
                            }, operate: false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });
            $("#do_status").click(function(){
                var ids = Table.api.selectedids(table);

                Fast.api.open('disassemble/money/do_status?ids='+ids, '批量录入', {area:["80%", "80%"]});
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        do_status: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
